<!--# 
layout("/layout/default.html",{"menu":["acl","role_admin"],"breadcrumbs":[{"name":"角色列表","url":"role/list"},{"name":obj.data.role == null ? "添加角色" : "编辑角色"}]}){ 
 #-->
<div class="space-4"></div>
<div class="row">
	<div class="col-md-8 col-md-offset-2 col-sm-12">
		<div class="panel panel-info">
			<div class="panel-heading">
				<h3 class="panel-title">${obj.data.role == null ? "添加角色" : "编辑角色"}</h3>
			</div>
			<div class="panel-body">
				<form id="addRoleForm" class="cmxform form-horizontal adminex-form" novalidate="novalidate">
					<div class="form-group ">
						<label class="control-label col-lg-3"> 角色名</label>
						<div class="col-lg-9">
							<input class="form-control" type="text" placeholder="请输入角色名" name="name" data-type='required' data-error='请输入角色名' value="${obj.data.role.name!}" ${obj.data.role== null ? "":"disabled"} />
						</div>
					</div>
					<div class="form-group ">
						<label class="control-label col-lg-3">角色描述</label>
						<div class="col-lg-9">
							<input type="text" class="hide" name="description" id="description">
							<textarea rows="25" class="form-control" placeholder="请输入角色描述" name="content">${obj.data.role.description!}</textarea>
						</div>
					</div>
					<input type="text" class="hide" id="id" name="id" value="${obj.data.role.id!}">
					<div class="pull-right" style="margin-right: 45px">
						<button type="button" class="btn btn-sm btn-primary" onclick="save(this)">
							<i class="fa fa-save"></i> 提交
						</button>
						<button class="btn btn-sm btn-default btn-back">
							<i class="fa fa-undo"></i> 返回
						</button>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	var editor;
	$(function() {
		//kindeditor 初始化
		KindEditor.ready(function(K) {
			editor = K.create('textarea[name="content"]', {
				uploadJson : getRootPath() + '/kind/upload'
			});
		})
	});
	function save(dom) {
		$('#description').val(editor.html());
		if ($('input').validation()) {
			if ($('#id').val() > 0) {
				$.post(getRootPath() + '/role/update', $('#addRoleForm').serialize(), function(result) {
					if (result.operationState == "SUCCESS") {
						location.href = getRootPath() + "/role/list";
					} else {
						validationFail(result.data.reason, dom);
					}
				}, 'json');
			} else {
				$.post(getRootPath() + '/role/add', $('#addRoleForm').serialize(), function(result) {
					if (result.operationState == "SUCCESS") {
						location.href = getRootPath() + "/role/list";
					} else {
						validationFail(result.data.reason, dom);
					}
				}, 'json');
			}
		}
	}
</script>
<!--# } #-->